package com.huizu.project.controller;

import com.huizu.common.core.controller.BaseController;
import com.huizu.common.core.domain.entity.SysUser;
import com.huizu.common.core.page.TableDataInfo;
import com.huizu.common.utils.SecurityUtils;
import com.huizu.project.domain.ProLd;
import com.huizu.project.domain.SysUserAuth;
import com.huizu.project.service.ExaminationApprovalService;
import com.huizu.project.service.ISysUserAuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Base64;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author: pjl
 * @Date: 2024/9/19
 * @ClassName: ExaminationApprovalController
 * @Description: 审批批阅
 */
@RestController
@RequestMapping("/project/examinationApproval")
public class ExaminationApprovalController extends BaseController {

    @Autowired
    private ExaminationApprovalService examinationApprovalService;

    @Autowired
    private ISysUserAuthService iSysUserAuthService;

    /**
     * 查询全部待审批的单子
     * @param proLd
     * @return
     */
    @GetMapping("/list")
    public TableDataInfo list(ProLd proLd) {
        SysUser user = SecurityUtils.getLoginUser().getUser();
        if (!SecurityUtils.isAdmin(user.getUserId())){
            SysUserAuth sysUserAuthPram = new SysUserAuth();
            sysUserAuthPram.setUserId(user.getUserId());
            List<SysUserAuth> auths = iSysUserAuthService.selectSysUserAuthList(sysUserAuthPram);
            List<String> bjs = auths.stream().filter(auth->auth.getType().equals("bj")).map(SysUserAuth::getBusId).collect(Collectors.toList());
            proLd.setBjIds(bjs);
        }
        startPage();
        List<ProLd> list = examinationApprovalService.list(proLd);
        return getDataTable(list);
    }
}
